package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestBody;

import ${package.Service}.${table.serviceName};
import ${cfg.voPackageName}.${cfg.voName};
import ${cfg.dtoPackageName}.${cfg.dtoName};
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName} ${cfg.serviceName};



    /**
     * 查询分页数据
     * @param page 分页参数
     * @param dto 查询条件信息
     * @return 分页数据
     */
    @ApiOperation(value = "查询分页数据")
    @RequestMapping(value = "/page")
    public IPage<${cfg.voName}> findListByPage(Page page,${cfg.dtoName} dto){
        return ${cfg.serviceName}.findListByPage(page, dto);
    }

    /**
     * 查询列表数据
     * @param dto 查询条件信息
     * @return 列表数据
     */
    @ApiOperation(value = "查询列表数据")
    @RequestMapping(value = "/list")
    public List<${cfg.voName}> findList(${cfg.dtoName} dto){
        return ${cfg.serviceName}.findList(dto);
    }

    /**
     * 新增数据
     * @param dto 主键id
     * @return 返回操作是否成功
     */
    @ApiOperation(value = "新增数据")
    @RequestMapping(value = "/add")
    public boolean add(@RequestBody ${cfg.dtoName} dto){
        return ${cfg.serviceName}.add(dto);
    }


    /**
     * 根据id查询
     * @param id 主键id
     * @return ${cfg.voName}
     */
    @ApiOperation(value = "根据id查询数据")
    @RequestMapping(value = "/findById")
    public ${cfg.voName} findById(@RequestParam("id") int id) {
          return ${cfg.serviceName}.findById(id);
    }

    /**
     * 更新数据
     * @param dto 主键id
     * @return 返回操作是否成功
     */
    @ApiOperation(value = "更新数据")
    @RequestMapping(value = "/update")
    public boolean update(@RequestBody ${cfg.dtoName} dto){
        return ${cfg.serviceName}.edit(dto);
    }


    /**
     * 根据主键id删除
     * @param id 主键id
     * @return 返回操作是否成功
     */
    @ApiOperation(value = "根据主键id删除")
    @RequestMapping(value = "/delete")
    public boolean deleteById(@RequestParam("id") int id){
        return ${cfg.serviceName}.deleteById(id);
    }




}
</#if>
